package com.beerandjesus.sportofkings.handicapper.dao;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Date: Jun 8, 2012
 * Time: 1:11:32 PM
 */
public class ConnectionManagerImpl implements ConnectionManager {

    private DataSource turfSireDataSource;
    private DataSource jockeyDataSource;


    public Connection getTurfSireDatabaseConnection() {
        try {
            return getTurfSireDataSource().getConnection();
        } catch (SQLException e) {
            throw new DatabaseException("Error getting connection to the turf sire database", e);
        }
    }

    public void releaseConnection(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                // Ignore this for now
            }
        }
    }

    public void init() {
    }

    public Connection getJockeyDatabaseConnection() {
        try {
            return getJockeyDataSource().getConnection();
        } catch (SQLException e) {
            throw new DatabaseException("Error getting connection to the jockey database", e);
        }
    }


    public DataSource getTurfSireDataSource() {
        return turfSireDataSource;
    }

    public void setTurfSireDataSource(DataSource turfSireDataSource) {
        this.turfSireDataSource = turfSireDataSource;
    }

    public DataSource getJockeyDataSource() {
        return jockeyDataSource;
    }

    public void setJockeyDataSource(DataSource jockeyDataSource) {
        this.jockeyDataSource = jockeyDataSource;
    }
}
